<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>安全检查</title>
<style>
.content_table {
	border: 1px solid #8DB2E3
}

.content_table td {
	height: 24px;
	padding: 5px
}

.content_table {
	width: 100%;
	border-collapse: collapse
}

.grid th {
	background: #E7F3FE;
	height: 27px;
	line-height: 27px;
	border: 1px solid #8DB2E3;
	padding-left: 5px
}

.content_table td {
	border: 1px solid #8DB2E3;
	padding-left: 5px
}
</style>
</head>
<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">安全检查</div>
		</div>
	</div>
	
	<div class="new-form">
			<form id="ff" method="post">
				<table class="content_table" id="content_table">
				</table>
			</form>
			<div style="text-align: center;">
				<a href="#" class="d-btn btn-blue" onclick="savePro()">保存</a>
			</div>
	</div>
</body>
<script th:inline="javascript">
	var currentprojectitem = [[${projectItem}]];
	var projectitemchild = [[${projectItemChild}]];
	var date = [[${date}]];
	
	$(document).ready(function() {
		$.ajax({
			type : 'GET',
			url : "../inspectionitem",
			data : {status:2},
			contentType : "application/json",
			success : function(data) {
				items = data.rows;
				var html="";
				var _html="";
				$.each(items,function(i,val){
					if(val.type==0){
						html+='<tr><td style="width:95%;">'+val.content+'</td><td class="safe"><input type="hidden" class="itemid" value="'+val.id+'" /><input type="hidden" class="type" value="check" /><input class="easyui-checkbox content"/></td></tr>';
					}
					if(val.type==1){
						html+='<tr><td colspan=2 style="border-width: 0px 0px 0px 0px;" >'+val.content+'</td></tr><tr><td colspan=2 class="safe"  style="border-width: 0px 0px 1px 0px;"><input type="hidden" class="itemid" value="'+val.id+'" /><input type="hidden" class="type" value="text" /><input class="easyui-textbox content" data-options="multiline:true" style="width: 100%;height:50px;"/></td></tr>';
					}
					
					if(val.type==0){
						_html+='<tr><td style="width:95%;">'+val.content+'</td><td class="safe"><input type="hidden" class="'+val.id+'" /><input class="easyui-textbox content" data-options="readonly:true"/></td></tr>';
					}
					if(val.type==1){
						_html+='<tr><td colspan=2 style="border-width: 0px 0px 0px 0px;">'+val.content+'</td></tr><tr><td colspan=2 class="safe" style="border-width: 0px 0px 1px 0px;"><input type="hidden" class="'+val.id+'" /><input class="easyui-textbox content" data-options="multiline:true,readonly:true" style="width: 100%;height:50px;"/></td></tr>';
					}
				});
				html+='</tr><tr><td  colspan="2" style="border-width: 0px 0px 0px 0px;">上传图片：</td></tr><tr><td colspan=2 style="border-width: 0px 0px 0px 0px;"><input class="easyui-filebox" data-options="prompt:\'添加图片\',buttonText:\'选择图片\',multiple:true,accept:\'image/*\'" id="images" name="images" style="width: 100px;"/></td></tr>';
				html+='</tr><td style="width:95%;">是否推送至预警</td><td><input type="checkbox" name="tosafe" id="tosafe" style="height:20px;"/></td></tr>';
				$('#content_table').append(html);
				$.parser.parse('#content_table');
			},
			dataType : "json"
		});
	});
	
	function savePro() {
		var formData = new FormData();
		var arr = new Array();
		$("#content_table").find(".safe").each(function(i){
			var safe = {};
			safe.projectitemid= currentprojectitem.id;
			if(projectitemchild.id>0){
				safe.projectitemchildid= projectitemchild.id;
			}
			safe.itemid=$(this).find(".itemid").val();
			if($(this).find(".type").val()=="check"){
				if($(this).find('.checkbox-checked').length>0){
					safe.content = true;
				}else{
					safe.content = false;
				}
				
			}
			if($(this).find(".type").val()=="text"){
				safe.content = $(this).find(".content").val();
			}
			arr.push(safe);
		});
		formData.append("arrstr",JSON.stringify(arr));
		formData.append("inspectiondate",date);
		var images = document.getElementById("filebox_file_id_1").files;
		for(var i=0;i<images.length;i++){
			formData.append('images',images[i]);
		}
		var tosafe = $("#tosafe").is(":checked");
		if(tosafe){
			formData.append("status",2);
		}else{
			formData.append("status",1);
		}
		$.ajax({
			type : 'POST',
			url :  "../safetyinspectionSave.do",
			cache : false,
			data : formData,
			processData : false,
			contentType : false,
			success : function(data) {
				if (data.success) {
					$.messager.alert('保存安全检查', '保存安全检查成功', 'success');
				} else {
					$.messager.alert('保存安全检查', '保存安全检查失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	}

	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
	$.extend($.fn.textbox.defaults.rules, {
	     number: {//value值为文本框中的值
	           validator: function (value) {
	          var reg = /^\d+(\.\d+)?$/;
	           return reg.test(value);
	       },
       message : "请输入数字"
   },
   percent:{
   	validator: function (value, param) {
   		var percent = 100;
           return parseFloat(value)<=parseFloat(percent);

       },
       message: '不能超过100%'
   }
   });

</script>
</html>